package com.dongzili.query.custom.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dongzili.query.common.base.BaseController;
import com.dongzili.query.common.config.mybatisplus.MybatisPlusUtil;
import com.dongzili.query.common.vo.PageRequest;
import com.dongzili.query.common.vo.R;
import com.dongzili.query.custom.domain.Relation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/relation")
public class RelationController {

    @PostMapping("/query")
    public R<?> query(@RequestBody PageRequest<Relation> req) {
        LambdaQueryWrapper<Relation> wrapper = new LambdaQueryWrapper<>(req.getEntity());
        if (req.getLikeEntity() != null) {
            wrapper.like(Relation::getResName, req.getLikeEntity().getResName());
        }
        return R.success(MybatisPlusUtil.getMapper(Relation.class).selectPage(new Page<>(req.getCurrent(), req.getSize()), wrapper));
    }

}
